﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    @*<link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">*@
    <link href="~/layuimini/lib/layui-v2.6.3/css/layui.css" rel="stylesheet" />
    @*<link rel="stylesheet" href="../../css/public.css" media="all">*@
    <link href="~/layuimini/css/public.css" rel="stylesheet" />

    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form" lay-filter="formTest">
        <div class="layui-form-item" hidden>
            <label class="layui-form-label required">ID</label>
            <div class="layui-input-block">
                <input type="text" name="ID" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">菜单标题</label>
            <div class="layui-input-block">
                <input type="text" name="Title" lay-verify="required" lay-reqtext="菜单标题不能为空" placeholder="请输入菜单标题" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">描述</label>
            <div class="layui-input-block">
                <input type="text" name="Description" lay-verify="required" lay-reqtext="描述不能为空" placeholder="请输入描述" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">等级</label>
            <div class="layui-input-block">
                <input type="text" name="Level" lay-verify="required" lay-reqtext="等级不能为空" placeholder="请输入等级" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">排序</label>
            <div class="layui-input-block">
                <input type="text" name="Sort" lay-verify="required" lay-reqtext="排序不能为空" placeholder="请输入排序" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">访问地址</label>
            <div class="layui-input-block">
                <input type="text" name="Href" lay-verify="required" lay-reqtext="访问地址能为空" placeholder="请输入访问地址" value="" class="layui-input">
            </div>
        </div>

       
        <div class="layui-form-item">
            <label class="layui-form-label ">图标样式</label>
            <div class="layui-input-block">
                <input type="text" name="Icon" lay-verify="required" lay-reqtext="图标样式不能为空" placeholder="请输入图标样式" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label ">目标</label>
            <div class="layui-input-block">
                <input type="text" name="Target" lay-verify="required" lay-reqtext="目标不能为空" placeholder="请输入目标" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父级菜单</label>
            <div class="layui-input-block">
                <select name="ParentId" id="parentSelect">
                    <option value=""></option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    @*<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>*@
    <script src="~/layuimini/lib/layui-v2.6.3/layui.js"></script>

    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;
            if (parent.menuInfoId) {
                //异步获取修改菜单信息数据
                $.ajax({
                    url: 'http://localhost:47365/api/MenuInfo/GetUpdateMenuInfo',
                    type: 'get',
                    data: {
                        menuInfoId: parent.menuInfoId
                    },
                    success: function (res) {

                        //赋值父级菜单
                        var menuInfoOptions = res.data.menuInfoOptions;
                        for (var i = 0; i < menuInfoOptions.length; i++) {
                            $('#parentSelect').append('<option value="' + menuInfoOptions[i].id + '">' + menuInfoOptions[i].title + '</option>');
                        }

                        //表单赋值
                        form.val("formTest", {
                            "ID": res.data.menuInfo.id
                            , "Title": res.data.menuInfo.title
                            , "Description": res.data.menuInfo.description
                            , "Level": res.data.menuInfo.level
                            , "Sort": res.data.menuInfo.sort
                            , "Href": res.data.menuInfo.href
                            , "Icon": res.data.menuInfo.icon
                            , "Target": res.data.menuInfo.target
                            , "ParentId": res.data.menuInfo.parentId

                        });
                    }

                });
            }
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var index = layer.alert('确定提交', {
                    title: '提示'
                }, function () {

                   

                    //请求服务器更新菜单
                    $.ajax({
                        url: 'http://localhost:47365/api/MenuInfo/UpdateMenuInfo',
                        data: data.field,
                        type: 'post',
                        success: function (res) {
                            if (res.isSuccess) {
                                // 关闭弹出层
                                layer.close(index);

                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                //调用父级页面的刷新方法
                                parent.reLoadTable();
                            } else {
                                layer.msg('修改失败');
                            }
                        }
                    });

                });

                return false;
            });

        });</script>
</body>
</html>